package com.soFun;

import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;
import org.springframework.stereotype.Service;

// 定义一个 AI 服务接口
interface MyAiService {
    String generateText(String input);
}

@Service
public class LangChain4jService {
    private final MyAiService myAiService;

    public LangChain4jService() {
        // 创建 OpenAI 聊天模型
        ChatLanguageModel model = OpenAiChatModel.withApiKey("your_openai_api_key");
        // 创建 AI 服务实例
        this.myAiService = AiServices.create(MyAiService.class, model);
    }

    public String generate(String input) {
        // 调用 AI 服务生成文本
        return myAiService.generateText(input);
    }
}